<#include '/share.include' />
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:replace="v1/include/header :: all_head(xx维护)">
</head>
<body>
<!-- Content Header (Page header) -->
<section class="content-header">
    <h1 th:replace="v1/include/header :: all_t_h"></h1>
    <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-dashboard"></i> 系统管理</a></li>
        <li class="active">xx管理</li>
    </ol>
</section>

<!-- Main content -->
<section class="content">
    <div class="box">
        <div class="box-header">
            <h3 class="box-title">xx列表</h3>
            <br><br>
            <button class="btn btn-success btn-sm" id="add${className}"><i class="fa fa-plus"></i> &nbsp;&nbsp;添加xx</button>
        </div>
        <!-- /.box-header -->
        <div class="box-body">
            <table id="${classNameLow}List" class="table table-bordered table-striped" data-striped="true"
                  >
                <thead>
                <tr>
                    <th>序号</th>
                    <#list columns as column>
                        <th>${column.remarks}</th>
                    </#list>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                <tr th:each="entity,stat :${r"${page.entityList}"}">
                    <td th:text="${r"${stat.count}"}">1</td>
                <#list columns as column>
                    <#if column.pk>
                    <#else>
                       <#if column.isDateTimeColumn>
                                <td>
                                    <span th:if="${r"${entity."}${column.columnNameFirstLower} !=null}"  th:text="${r"${#dates.format(entity."}${column.columnNameFirstLower},'yyyy-MM-dd')}">${column.remarks}
                                    </span>
                                </td>
                                <#else>
                                    <#if column.columnNameFirstLower='youxbz'>
                                        <td >
                                            <span class="label label-info" th:class="${r"$"}{entity.youxbz==1 ? 'label label-info':'label label-danger'}" th:text="${r"$"}{entity.youxbz==1 ? '有效':'无效'}"></span>
                                            &nbsp;&nbsp;
                                            <span data-toggle="tooltip" title="作废或恢复xx" th:class="${r"$"}{entity.youxbz==1 ? 'btn btn-xs btn-danger':'btn btn-xs btn-info'}"
                                            th:onclick="'zf${className}(\''+${r"$"}{entity.id}+'\',\''+${r"$"}{entity.youxbz==1?1:0}+'\');'" >
                                            <i class="fa  fa-arrow-right"></i>
                                            <span th:text="${r"$"}{entity.youxbz==1 ? '作废':'恢复'}""></span></span>
                                        </td>
                                        <#else>
                                            <td th:text="${r"${entity."}${column.columnNameFirstLower}}">${column.remarks}</td>
                                    </#if>
                            </#if>
                    </#if>

                </#list>

                <td>
                    <div>

                            <span data-toggle="tooltip" title="编辑xx信息" class="btn btn-xs btn-info"
                                  th:onclick="'edit${className}(\''+${r"${entity.id}"}+'\');'">

                                <i class="fa fa-edit"></i> 编辑</span>
                        <span data-toggle="tooltip" title="删除xx" class="btn btn-xs btn-danger"
                              th:onclick="'del${className}(\''+${r"${entity.id}"}+'\');'"><i
                                class="fa fa-trash-o"></i> 删除</span>

                    </div>
                    <div>
                        <span><i class="fa fa-lock"></i></span>
                    </div>
                </td>
                </tbody>
            </table>
            <!---分页工具条-->
            <div id="pagination" class="col-sm-2"></div>
        </div>


    </div>
</section>

<!-- 新增或修改的模态框 -->
<div class="modal fade" id="${classNameLow}Modal" tabindex="-1" role="dialog"
     aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"
                        aria-hidden="true">&times;
                </button>
                <h4 class="modal-title text-center" id="${classNameLow}modelHead">添加xx</h4>
            </div>
            <div class="modal-body">

                <input type="hidden" name="page_${classNameLow}_url" value=""/>
                <input type="hidden" name="type" value=""/>

                <form id="add_edit_form" class="form-horizontal" role="form">

                    <#list columns as column>

                    <div class="form-group">
                        <label for="${column.columnNameFirstLower}" class="col-sm-2 control-label">${column.remarks}</label>
                        <div class="col-sm-10">
                            <#if  column.isDateTimeColumn>
                                <input type="date" class="form-control" name="${column.columnNameFirstLower}" value="" id="${column.columnNameFirstLower}"
                                       placeholder="请输入${column.remarks}">
                                <#else>
                                    <input type="text" class="form-control" name="${column.columnNameFirstLower}" value="" id="${column.columnNameFirstLower}"
                                           placeholder="请输入${column.remarks}">
                            </#if>
                        </div>
                    </div>

                    </#list>

                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary" data-dismiss="modal">关闭</button>
                <button type="submit" class="btn btn-success" id="imgSubmit">确定</button>
            </div>
        </div>
    </div>
</div>

<div th:replace="v1/include/header :: all_js"></div>

<script th:inline="javascript">

${r"$(function () {"}
        //提示框
    ${r" $"}("[data-toggle='tooltip']").tooltip();

    //分页工具条设置
    var options = {
        bootstrapMajorVersion:1,
        currentPage: [[${r" $"}{page.number}+1]],//当前页数
        totalPages: [[${r" $"}{page.totalPages}==0?1: ${r" $"}{page.totalPages}]],//总页数
        numberOfPages:5,    //最多显示Page页
        size:"normal" ,//设置控件的显示大小，是个字符串. 允许的值: mini, small, normal,large。值：mini版的、小号的、正常的、大号的。
        itemTexts: function(type, page, current) { //修改显示文字
        switch (type) {
            case "first":
                return "首页";
            case "prev":
                return "上一页";
            case "next":
                return "下一页";
            case "last":
                return "末页";
            case "page":
                return page;
        }
    },
    pageUrl: function(type, page, current){
        return "/sys/${classNameLow}/page?page="+page;
    }
    };
    $("#pagination").bootstrapPaginator(options);


    ${r"$"}("#add${className}").click(function () {
        reloadModelData("/sys/${classNameLow}/add", "添加xx", "添加",null,"add");
        ${r"$"}("#${classNameLow}Modal").modal("show");
    });

    //确认按钮
    ${r"$"}("#imgSubmit").click(function () {
        var _page_${classNameLow}_url = ${r"$"}("input[name='page_${classNameLow}_url']").val();
        var _type = ${r"$"}("input[name='type']").val();
        <#list columns as column>
        var ${r"_"}${column.columnNameFirstLower} = ${r"$"}("input[name='${column.columnNameFirstLower}']").val();
        </#list>
        var _data;
        _data={
            <#list columns as column>
                ${column.columnNameFirstLower}: ${r"_"}${column.columnNameFirstLower}<#sep>,
            </#list> };


        //验证非空
        //        if (_type == 'add') {
        //            if (!checkAccount(_bianh, _xingm, _mim)) {
        //                return false;
        //            }
        //        }

        ${r"$"}.ajax({
            type: "post",
            url: _page_${classNameLow}_url,
            cache: false,
            dataType: "json",
            data: _data,
            success: function (data) {
                if (data.code == '1') {
                    ${r"$"}("#${classNameLow}Modal").modal("hide");
                    window.location.href = window.location.href;
                } else {
                    alert(data.resultObject);
                }
            },
            error:function (data) {
                alert(data.resultObject);
            }
        });
    });
});
<#list columns as column>
<#if column.columnNameFirstLower='youxbz'>
    //作废恢复xx
    function zf${className}(Id,_bz) {

    method.msg_confirm("提示","你确定要作废或恢复此xx吗？",function(){
        ${r"$"}.ajax({
            type:"POST",
            url:"/sys/${classNameLow}/zouf",
            dataType:"json",
            data:{id:Id,bz:_bz},
            cache:false,
            success:function(data){
                var code = data.code || data.result.code;
                var msg = data.msg || data.result.msg;
                if(code== '1'){
                    method.msg_pro("操作成功！",1000,function () {
                        window.location.href = window.location.href;
                    });
                }else{
                    method.msg_alert("提示", msg);
                }
            },
            error:function (data) {
                var msg = data.msg || data.result.msg;
                method.msg_alert("提示", msg);
            }
        });
    });
}
</#if>
</#list>

//删除用户
function del${className}(Id) {
    ${r"if "}(confirm("你确定要删除此xx吗？")) {

        ${r"$"}.ajax({
            type:"POST",
            url:"/sys/${classNameLow}/del",
            dataType:"json",
            data:{id:Id},
            cache:false,
            success:function(data){
                if(data.code== '1'){
                    window.location.href=window.location.href;
                }else{
                    alert(data.resultObject);
                }
            },
            error:function (data) {
                alert(data.resultObject);
            }
        });
    }
}
//编辑用户
function edit${className}(Id) {

    ${r"$"}.ajax({
        type:"POST",
        url:"/sys/${classNameLow}/get",
        dataType:"json",
        data:{id:Id},
        cache:false,
        success:function(data){
            if(data.code== '1'){
                reloadModelData("/sys/${classNameLow}/edit", "编辑xx", "更新",data.resultObject, "edit");
                ${r"$"}("#${classNameLow}Modal").modal("show");
            }else{
                alert(data.resultObject);
            }
        },
        error:function (data) {
            alert(data.resultObject);
        }
    });
}

////验证数据
//function checkAccount(bianh, xingm, password) {
//    ${r"if"} (bianh == '') {
//        ${r"$"}("input[name='bianh']").focus();
//        alert("登录名不能为空");
//        return false;
//    }
//    return true;
//}
//加载模态框的数据
function reloadModelData(url,title,btntext,data,type) {
    ${r"$"}("#${classNameLow}Modal #${classNameLow}modelHead").text(title);
    ${r"$"}("#${classNameLow}Modal #imgSubmit").text(btntext);
    ${r"$"}("input[name='page_${classNameLow}_url']").val(url);
    ${r"$"}("input[name='type']").val(type);

    ${r"if"}(data !=null && data !="" && type == "edit")
    {
        <#list columns as column >
            <#if column.isDateTimeColumn>
                ${r"$"}("input[name='${column.columnNameFirstLower}']").val(new Date(data.${column.columnNameFirstLower}).Format("yyyy-MM-dd"));
            <#else>
                ${r"$"}("input[name='${column.columnNameFirstLower}']").val(data.${column.columnNameFirstLower});
            </#if>
        </#list>
        //设置是否可编辑
        $("input[name='id']").attr("disabled", true);
    }else{
        //清空界面上的内容
        <#list columns as column >
        ${r"$"}("input[name='${column.columnNameFirstLower}']").val("");
    </#list>
        //设置是否可编辑
        $("input[name='id']").attr("disabled", false);
    }
}
</script>
</body>
</html>